#version 330 core
// vim: set filetype=cpp :vim

layout(lines) in;
layout(triangle_strip, max_vertices=34) out;

uniform mat4 mProj;
uniform float umpp;

in float outr[];

void main(void) {
	vec3 vcent0=gl_in[0].gl_Position.xyz/gl_in[0].gl_Position.w;
	vcent0+=vec3(0.0, 0.0, outr[0]);
	vec3 vcent1=gl_in[1].gl_Position.xyz/gl_in[1].gl_Position.w;
	vcent1+=vec3(0.0, 0.0, outr[1]);
	vec2 u;
	if(length(vcent0.xy-vcent1.xy)<.001) {
		u=vec2(1.0, 0.0);
	} else {
		u=normalize(vcent0.xy-vcent1.xy);
	}
	vec2 v=vec2(u.y, -u.x);
	for(int i=0; i<17; i++) {
		int j=i/2+(i%2)*(32-i);
		float a=j*2*3.14159/32;
		gl_Position=mProj*vec4(vcent0+vec3(cos(a)*u+sin(a)*v, 0.0)*umpp, 1.0);
		EmitVertex();
	}
	for(int i=15; i<32; i++) {
		int j=i/2+(i%2)*(32-i);
		float a=j*2*3.14159/32;
		gl_Position=mProj*vec4(vcent1+vec3(cos(a)*u+sin(a)*v, 0.0)*umpp, 1.0);
		EmitVertex();
	}
	EndPrimitive();
}

